package org.dochandler.test.tester;

import static org.junit.Assert.assertEquals;

import org.dochandler.service.domain.Officer;
import org.dochandler.service.domain.constants.Constants;
import org.dochandler.service.domain.mission.AccessTime;
import org.dochandler.service.domain.mission.MissionRequest;
import org.dochandler.test.service.MissionRequestServiceTest;
import org.dochandler.test.service.core.MissionRequestServiceTestImpl;
import org.esfinge.guardian.context.AuthorizationContext;
import org.esfinge.guardian.context.WrappedObj;
import org.esfinge.guardian.exception.AuthorizationException;
import org.junit.Before;
import org.junit.Test;

public class WorkingTimeTester {
	
	private MissionRequest missionRequest;
	private Officer officer;
	
	@Before
	public void setUp() {
		missionRequest = new MissionRequest();
		officer = new Officer();
	}
	
	/**
	 * Test of the Security Policy Id SP05
	 *
	 */
	@Test
	public void requestMissionInWorkingTimeTest() {
		WrappedObj<AccessTime> w1 = AuthorizationContext.wrapAsEnvironmentProp(Constants.ACCESS_TIME.val(), new AccessTime(8, 0, 0) );
		WrappedObj<Officer> w2 = AuthorizationContext.wrapAsSubjectProp(Constants.OFFICER.val(), officer);
		
		MissionRequestServiceTest mrs = AuthorizationContext.guardObject(new MissionRequestServiceTestImpl(officer), new Object[] {officer}, w1, w2);
		
		assertEquals("The result must be true", true, mrs.validInWorkingTime() );
	}
	
	
	/**
	 * Test of the Security Policy Id SP05
	 *
	 */
	@Test(expected=AuthorizationException.class)
	public void requestMissionNotInWorkingTimeTest() {
		WrappedObj<AccessTime> w1 = AuthorizationContext.wrapAsEnvironmentProp(Constants.ACCESS_TIME.val(), new AccessTime(18, 0, 0) );
		WrappedObj<Officer> w2 = AuthorizationContext.wrapAsSubjectProp(Constants.OFFICER.val(), officer);
		
		MissionRequestServiceTest mrs = AuthorizationContext.guardObject(new MissionRequestServiceTestImpl(officer), new Object[] {officer}, w1, w2);
		
		mrs.validInWorkingTime();
	}
	
	
	/*
	 * SETTERS AND GETTERS 
	 */

	public MissionRequest getMissionRequest() {
		return missionRequest;
	}

	public void setMissionRequest(MissionRequest missionRequest) {
		this.missionRequest = missionRequest;
	}

	public Officer getOfficer() {
		return officer;
	}

	public void setOfficer(Officer officer) {
		this.officer = officer;
	}
	
}
